home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ComCtrls, ExtCtrls;
-
- const
- // Magic signatures
- D2Magic = $50505348;
- D3Magic = $44518641;
- D4Magic = $4768A6D8;
- B3Magic = $475896C8;
-
- // DCU record tags
- Tag_End = $61;
-
- type
- TForm1 = class(TForm)
- Scan: TButton;
- StatusBar1: TStatusBar;
- TreeList: TListView;
- procedure ScanClick(Sender: TObject);
- private
- { Private declarations }
- Scanning: Boolean;
- procedure ScanDrive (const Path: String);
- procedure FoundOne (const PathName: String);
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.ScanClick (Sender: TObject);
- var
- p: PChar;
- szBuff: array [0..255] of Char;
- begin
- Scanning := not Scanning;
- if Scanning then begin
- Scan.Caption := 'Stop Scan!';
- Screen.Cursor := crHourGlass;
- TreeList.Items.Clear;
- TreeList.Items.BeginUpdate;
-
- try
- p := szBuff;
- GetLogicalDriveStrings (sizeof (szBuff), szBuff);
- while Scanning and (p^ <> #0) do begin
- if GetDriveType (p) = Drive_Fixed then ScanDrive (p);
- Inc (p, 4);
- end;
- finally
- Scanning := False;
- Scan.Caption := 'Scan!';
- Screen.Cursor := crDefault;
- TreeList.Items.EndUpdate;
- end;
- end;
- end;
-
- procedure TForm1.FoundOne (const PathName: String);
- var
- eof: Byte;
- S: String;
- Valid: Boolean;
- fs: TFileStream;
- Item: TListItem;
- Magic: array [0..2] of LongInt;
- begin
- fs := TFileStream.Create (PathName, fmOpenRead);
- try
- fs.Read (Magic, sizeof (Magic));
- fs.Position := fs.Size - 1;
- fs.Read (eof, sizeof (eof));
- Valid := (Magic [1] = fs.Size) and (eof = Tag_End);
- finally
- fs.Free;
- end;
-
- if Valid then begin
- Item := TreeList.Items.Add;
- Item.Caption := PathName;
- case Magic [0] of
- D2Magic: S := 'Delphi 2';
- D3Magic: S := 'Delphi 3';
- D4Magic: S := 'Delphi 4';
- B3Magic: S := 'C++ Builder 3';
- else S := '???' + IntToHex (Magic [0], 8);
- end;
- Item.SubItems.Add (S);
-
- if Magic [2] = $ffffffff then S := 'Invalid date/time' else
- S := FormatDateTime ('dddd, mmmm d, yyyy, hh:mm AM/PM', FileDateToDateTime (Magic [2]));
- Item.SubItems.Add (S);
- end;
- end;
-
- procedure TForm1.ScanDrive (const Path: String);
- var
- Res: Integer;
- SR: TSearchRec;
- begin
- Application.ProcessMessages;
- StatusBar1.Panels [0].Text := 'Scanning ' + Path;
- Res := FindFirst (Path + '*.*', faAnyFile, SR);
- try
- while Scanning and (Res = 0) do begin
- if SR.Name [1] <> '.' then begin
- if UpperCase (ExtractFileExt (SR.Name)) = '.DCU' then FoundOne (Path + SR.Name) else
- if ((SR.Attr and faDirectory) <> 0) then ScanDrive (Path + SR.Name + '\');
- end;
- Res := FindNext (SR);
- end;
- finally
- FindClose (SR);
- end;
- end;
-
- end.
-
-
-